<?php
error_reporting(1);

require_once(APPPATH . '/controllers/test/Toast.php');

class Classified_tests extends Toast {
	 
	var $CI;
	

	function Classified_tests() {
		
		parent::Toast(__FILE__);
		$this->load->model('Classified_model','',TRUE);
		$this->load->model('Classifiedscatg_model', '', TRUE);
		// Load any models, libraries etc. you need here
	}

	function _pre() {

		 
	}
	function _post(){
		 
	}
	// Add advertisement test
	function test_save() {
	
		$result = "";
		$advertisement['title'] = 'LG 40 LCD TV for sale';
		$advertisement['description'] = "hardly used 40 inches LCD TV.";
		$advertisement['price'] = 700;
		$advertisement['categoryID'] = 1;
		$advertisement['advertiserID'] = 1;
		$advertisement['isSpecialDiscount'] = true;
		$advertisement['percentage'] = 10;
		
		$id = $this->Classified_model->save($advertisement);
		
		$result = $result . "Add new adv in ID : " . $id;
		$this->message = $result;
		$this->_assert_equals($id, 3);
	}
	
	// Update advertisement test
	function test_update(){
		$result = $this->Classified_model->get_by_id (2);
		$newadv = array();
		foreach ($result as $adv){
			$newadv = $adv;
			$newadv['title'] = 'Sony Player for sale';
		}
		//$newadv['title'] = $adv['title'];
		//$newadv['advid'] = $adv['advid'];
		$this->Classified_model->update($newadv);
		
		$updatedresult = $this->Classified_model->get_by_id (2);
		
		foreach ($updatedresult as $updatedadvertisement){
			$result = "";
			$this->message = $updatedadvertisement['title'] .  ' adversier:' . $updatedadvertisement['firstName'];
			$this->_assert_equals($updatedadvertisement['title'],'Sony Player for sale');
		}	
	}
	// delete advertisement test
	
	function test_delete(){
		$total_records = $this->Classified_model->count_all();
		
		$this->Classified_model->delete(3);
		$result = "";
		$this->message = "No of records left in total " . $this->Classified_model->count_all();
		$this->_assert_equals($total_records - 1, $this->Classified_model->count_all());
		
	}
	
	//get by advertiser id
	function test_advertiser()
	{
		$this->Classified_model->get_by_advertiserid(1);
	}
	
	//test pagination 
	function test_pagedlist()
	{
		$cond = array();
		//$cond['categoryID'] = 1;
		//$cond['advertiserID'] = 1;
		
		$count = $this->Classified_model->count_all();
		
		//$cond['advid'] = 2;
		$limit = $count;
		$offset = 0;
		
		
		$displayMsg = '';
		$result = $this->Classified_model->get_result($cond, $limit, $offset);
		
		foreach ($result as $row)
		{
			$displayMsg = $displayMsg . "-" . $row['title'];
			
		}
		$this->message = 'No of title==>' . $displayMsg . ' + No of rows==>' . count($result);
	}
	
	// test price range
	function test_pricerange()
	{
		$cond = array();
		$cond['low'] = 500;
		$cond['high'] = 1200;
		$result = $this->Classified_model->get_by_pricerange($cond);
		foreach ($result as $row)
		{
			$displayMsg = $displayMsg . "-" . $row['title'];
				
		}
		$this->message = 'No of title==>' . $displayMsg;
	}
	//test search
	function test_search()
	{
		$search = 'graphic card';
		$displayMsg = "";
		$result = $this->Classified_model->get_search_result($search);
		foreach ($result as $row)
		{
			$displayMsg = $displayMsg . "-" . $row['title'];
		
		}
		$this->message = 'No of result==>' . count($result) . ' Display Msg==>' . $displayMsg;
	}
	//add new category
	function test_addcatg()
	{
		$cat['cat_descriptions'] = 'Travel';
		$result = $this->Classifiedscatg_model->save($cat);
		$this->message = 'Cat ID'. $result;
		$this->_assert_equals(6, $result);
		
	}
	//update category
	function test_updatecatg()
	{
		$cat['cat_descriptions'] = 'Handmades';
		$cat['id'] = 3;
		$this->Classifiedscatg_model->update($cat);
		
	}
	//delete category
	function test_deletecatg()
	{
		
		$this->Classifiedscatg_model->delete(6);
		
		
	}

}
?>
